// oi-wiki 贪心算法 后悔法

package main

import (
	"container/heap"
	"fmt"
	"sort"
)

type f struct {
	d uint64
	p uint64
}

type subf []f

func (s subf) Len() int { return len(s) }

func (s subf) Less(i, j int) bool { return s[i].d < s[j].d }

func (s subf) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

var a [100005]f

type PriorityQueue []uint64

func (pq *PriorityQueue) Len() int { return len(*pq) }

func (pq *PriorityQueue) Less(i, j int) bool { return (*pq)[i] < (*pq)[j] }

func (pq *PriorityQueue) Swap(i, j int) { (*pq)[i], (*pq)[j] = (*pq)[j], (*pq)[i] }

func (pq *PriorityQueue) Push(x interface{}) {
	if v, ok := x.(uint64); ok {
		*pq = append(*pq, v)
	} else {
		panic("Push expects uint64")
	}
}

func (pq *PriorityQueue) Pop() interface{} {
	// old := *pq
	// n := len(old)
	// x := old[n-1]
	// *pq = old[0 : n-1]
	// return x

	// old := *pq
	n := len(*pq)
	x := (*pq)[n-1]
	*pq = (*pq)[0 : n-1]
	return x
}

func (pq *PriorityQueue) top() uint64 {
	// if pq.Len() == 0 {
	// 	panic("the heap is empty\n")
	// }
	return (*pq)[0]
}

func main() {
	// q := PriorityQueue{10, 12, 14, 6, 8}
	// heap.Init(&q)
	// for q.Len() > 0 {
	// 	fmt.Printf("len=%d, val=%d\n", len(q), q.top())
	// 	fmt.Printf(" %d \n", heap.Pop(&q))
	// }
	var n, i uint64
	fmt.Scanf("%d", &n)
	for i = 1; i <= n; i++ {
		fmt.Scanf("%d%d", &a[i].d, &a[i].p)
	}
	sf := a[1 : n+1]
	sort.Sort(subf(sf))
	var ans uint64
	ans = 0
	var q PriorityQueue
	heap.Init(&q)
	for i = 1; i <= n; i++ {
		if a[i].d <= uint64(q.Len()) {
			top := q.top()
			if top < a[i].p {
				ans += a[i].p - top
				heap.Pop(&q)
				heap.Push(&q, a[i].p)
			}
		} else {
			ans += a[i].p
			heap.Push(&q, a[i].p)
		}
	}
	fmt.Printf("%d\n", ans)
}
